#!/usr/bin/env python3
"""
依赖安装脚本
用于安装RAG系统所需的Python包
"""

import subprocess
import sys
import os

def install_package(package):
    """安装Python包"""
    try:
        subprocess.check_call([sys.executable, "-m", "pip", "install", package])
        print(f"✓ 成功安装 {package}")
        return True
    except subprocess.CalledProcessError as e:
        print(f"✗ 安装 {package} 失败: {e}")
        return False

def main():
    """主函数"""
    print("=" * 50)
    print("RAG系统依赖安装脚本")
    print("=" * 50)
    
    # 必需的包列表
    required_packages = [
        "langchain==0.3.0",
        "langchain-community",
        "qdrant-client",
        "python-dotenv",
        "PyPDF2",
        "dashscope"  # 阿里云百炼SDK
    ]
    
    print("开始安装依赖包...")
    print()
    
    success_count = 0
    total_count = len(required_packages)
    
    for package in required_packages:
        print(f"正在安装 {package}...")
        if install_package(package):
            success_count += 1
        print()
    
    print("=" * 50)
    print("安装结果汇总:")
    print(f"成功安装: {success_count}/{total_count}")
    print("=" * 50)
    
    if success_count == total_count:
        print("✓ 所有依赖包安装成功！")
        print()
        print("下一步:")
        print("1. 复制 .env.template 为 .env")
        print("2. 在 .env 文件中配置您的 DASHSCOPE_API_KEY")
        print("3. 运行 python run_rag.py 开始使用RAG系统")
    else:
        print("✗ 部分依赖包安装失败，请检查错误信息并手动安装")
    
    print()
    print("注意: 请确保您已激活 traval conda 环境")

if __name__ == "__main__":
    main()
